package com.lrkj.property.controller;

import io.swagger.annotations.ApiOperation;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.property.domain.RepairOrder;
import com.lrkj.property.service.IRepairOrderService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 报修单Controller
 *
 * @author yajun_ren
 * @date 2021-07-27
 */
@RestController
@RequestMapping("/property/repairOrder")
public class RepairOrderController extends BaseController {

    @Autowired
    private IRepairOrderService repairOrderService;

    /**
     * 查询报修单列表
     */
    @ApiOperation(value = "查询报修单列表", notes = "查询报修单列表")
    @PreAuthorize("@ss.hasPermi('property:repairOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairOrder repairOrder) {
        startPage();
        List<RepairOrder> list = repairOrderService.selectRepairOrderList(repairOrder);
        return getDataTable(list);
    }

    /**
     * 导出报修单列表
     */
    @ApiOperation(value = "导出报修单列表", notes = "导出报修单列表")
    @PreAuthorize("@ss.hasPermi('property:repairOrder:export')")
    @Log(title = "报修单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RepairOrder repairOrder) {
        List<RepairOrder> list = repairOrderService.selectRepairOrderList(repairOrder);
        ExcelUtil<RepairOrder> util = new ExcelUtil<RepairOrder>(RepairOrder.class);
        return util.exportExcel(list, "报修单数据");
    }

    /**
     * 获取报修单详细信息
     */
    @ApiOperation(value = "获取报修单详细信息", notes = "获取报修单详细信息")
    @PreAuthorize("@ss.hasPermi('property:repairOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(repairOrderService.selectRepairOrderById(id));
    }

    /**
     * 新增报修单
     */
    @ApiOperation(value = "新增报修单", notes = "新增报修单")
    @PreAuthorize("@ss.hasPermi('property:repairOrder:add')")
    @Log(title = "报修单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepairOrder repairOrder) {
        return toAjax(repairOrderService.insertRepairOrder(repairOrder));
    }

    /**
     * 修改报修单
     */
    @ApiOperation(value = "修改报修单", notes = "修改报修单")
    @PreAuthorize("@ss.hasPermi('property:repairOrder:edit')")
    @Log(title = "报修单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairOrder repairOrder) {
        return toAjax(repairOrderService.updateRepairOrder(repairOrder));
    }

    /**
     * 删除报修单
     */
    @ApiOperation(value = "删除报修单", notes = "删除报修单")
    @PreAuthorize("@ss.hasPermi('property:repairOrder:remove')")
    @Log(title = "报修单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(repairOrderService.deleteRepairOrderByIds(ids));
    }
}
